package com.hgd.security.evp.biz.service.impl;

import com.hgd.security.evp.auth.entity.CustomUserDetails;
import com.hgd.security.evp.auth.service.IUserService;
import com.hgd.security.evp.biz.biz.EvpUserBiz;
import com.hgd.security.evp.biz.entity.EvpUser;
import com.hgd.security.evp.common.util.EmptyUtil;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.core.userdetails.UserDetails;
import org.springframework.security.core.userdetails.UsernameNotFoundException;
import org.springframework.stereotype.Service;

@Service
@Slf4j
public class UserServiceImpl implements IUserService {

	@Autowired
	private EvpUserBiz evpUserBiz;
	
    @Override
    public UserDetails loadUserByUsername(String username) throws UsernameNotFoundException {
    	log.info("===================获取到token已进入自定义验证：" + username);

		EvpUser userByEAccount = evpUserBiz.getUserByEAccount(username);

		if(EmptyUtil.isEmpty(userByEAccount)){
			throw new UsernameNotFoundException("该用户不存在");
		}

		// 可以进行数据库请求
        return new CustomUserDetails(userByEAccount.getEvpAccount() ,userByEAccount.getEvpPassword(),
				userByEAccount.getId(),
				userByEAccount.getDeptId(),
        		null,
        		userByEAccount.getUserName(),
        		true, true, true, true, null);
    }
}